package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class TravelPaper {
    public static final int STATE_NORMAL = 0; //非头条状态
    public static final int STATE_HOT = 1; //头条状态

    private Long id;

    private String title;

    private String subTitle;

    private String coverUrl;

    @JsonFormat(pattern = "yyyy-MM-dd ", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime; //发布时间

    private Integer state; // 状态, 头条, 非头条

    private TravelPaperContent content;  //  与日报一对一关系

    public String getStateDisplay() {
        if (state == STATE_NORMAL) {
            return "非头条状态";
        } else {
            return "头条状态";
        }
    }

    public String getJsonString(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("releaseTime",releaseTime);
        map.put("state",state);
        return JSONUtils.toJSONString(map);
    }
}